package scau.erps.view.decision.sand;

import java.util.List;

import scau.erps.app.Erps;
import scau.erps.entity.Material;
import scau.erps.entity.Team;
import scau.erps.service.MaterialService;
import scau.erps.service.impl.MaterialServiceImpl;
import scau.erps.util.CalculateQuarter;

/**
 * 应付款沙盘模拟
 * @author DCJ
 *
 */
public class ReceivablePanel extends SandPanelTemplateFor4Q{
	private static final long serialVersionUID = 1L;
	public ReceivablePanel(){
		super();
		this.titleLabel.setText("应收款");
		this.setTextFieldValue();
	}
	@Override
	public void setTextFieldValue() {
		Team team = Erps.getCurrentTeam();	
		int team_Id = team.getId();
		int q1 = 0;
		int q2 = 0;
		int q3 = 0;
		int q4 = 0;
		MaterialService materialService = Erps.getIocInstance().get(MaterialServiceImpl.class);
		List<Material> materials =materialService.getMaterial(team_Id, null, "已入库"); 
		for (Material material : materials) {
			String payQuarter = material.getPayTime();
			String currentQuarter = Erps.getSand().getTime();
			int quarter = CalculateQuarter.getQuarter(payQuarter, currentQuarter);
			int amount = material.getNumber();
			if(quarter==0){
				q1=q1+amount;
			} 
			else if(quarter==1){
				q2=q2+amount; 
			}
			else if(quarter==2){
				q3=q3+amount;
			}
			else if(quarter==3){
				q4=q4+amount;
			}				
		}		
		this.jtx_1q.setText(Integer.toString(q1));		
		this.jtx_2q.setText(Integer.toString(q2));
		this.jtx_3q.setText(Integer.toString(q3));
		this.jtx_4q.setText(Integer.toString(q4));		
	}
}
